W6. Deterministic Pushdown Automata
1. Theory
1.1 From Finite Automata to Pushdown Automata
We already know that Finite State Automata (FSAs) can recognize regular languages. But FSAs have a fundamental limitation: they have only a fixed, finite amount of memory — precisely the current state. This makes certain languages impossible to recognize, such as
To go beyond regular languages, we need a model with more memory. The natural extension is to attach a stack to an FSA, producing a Pushdown Automaton (PDA). The name “pushdown” refers to the push-down nature of the stack, where new items are placed on top and the top item is always the one removed first.
Informally:
- FSA = finite control unit (states only)
- PDA = finite control unit + an infinite stack
The hierarchy of computational models, from weakest to most powerful, looks like:
- Combinational logic — no memory
- Finite State Automata — fixed, bounded memory (current state only)
- Pushdown Automata — unbounded stack memory (can grow without limit)
- Turing Machines — full read/write tape (most powerful)
PDAs sit exactly at the level above FSAs and can recognize context-free languages (CFLs), which include most programming language constructs. This is why PDAs are at the heart of compilers — the syntax of programming languages is context-free.
1.2 The Stack: A Refresher
A stack is a last-in, first-out (LIFO) data structure. Think of a stack of trays in a cafeteria: you can only add or remove from the top.
Operations:
- Push: Place a new symbol on top of the stack.
- Pop: Remove the top symbol from the stack (and “read” it at the same time).
A PDA’s stack starts with a special bottom-of-stack symbol
Example — push
- Initial stack:
(bottom only) - Push
: stack = (top to bottom) - Push
: stack = - Push
: stack = - Pop: removes
; stack =
The most recently pushed symbol is always the first to be removed. This LIFO property makes the stack ideal for matching nested structures like balanced parentheses.
Historical note: The concept of a stack was introduced by Alan Turing in his 1946 paper on the Automatic Computing Engine (ACE), where he called the operations BURY and UNBURY, and used them in the theory of subroutines.
1.3 Informal Description of a PDA
A PDA has three components:
- An input tape — a read-only, left-to-right sequence of symbols (the input string)
- A finite control unit — like an FSA, it keeps track of the current state
- A stack of infinite size — the extra memory; the control unit reads the top and replaces it
In each step, a PDA looks at three things simultaneously:
- The current state
- The next input symbol (or
for a “silent” move) - The top of the stack
Based on these three inputs, it:
- Moves to a new state
- Advances the input head (or stays in place for
-moves) - Replaces the top stack symbol with some string
Using the stack, a PDA can:
- Push symbols onto the stack (replace top
with , so is now on top) - Pop the top symbol (replace top
with , i.e., nothing) - Leave the stack unchanged (replace top
with ) - Make
-moves — transitions that consume no input, only modify the stack
Acceptance criteria: A string is accepted if, after reading it completely, the PDA is in an accepting (final) state. The stack content at the end does not matter for acceptance by final state.
1.4 Formal Definition of a PDA
A Pushdown Automaton is a 7-tuple:
where:
— finite set of states — finite input alphabet (the symbols the PDA reads from its tape) — finite stack alphabet (the symbols that can appear on the stack; note and may overlap) — the transition function (a partial function mapping to sets of possible outcomes) — the initial state — the initial stack symbol (bottom-of-stack marker, placed on the stack at the start) — the set of accepting (final) states
Reading the transition function: A transition
In state
, reading input symbol (or ), with stack symbol on top: move to state and replace with the string .
The graphical notation on arrows is:
- To push
onto the stack below : write (replace with ; now is on top) - To pop
: write (replace with nothing) - To leave the stack unchanged: write
Conditions on
- The stack always contains at least
is never removed from the stack- No additional copies of
are pushed onto the stack
1.5 Deterministic Pushdown Automata (DPDA)
The general PDA above is nondeterministic:
A PDA
- At most one transition at each step: For every
, every , and every , the set has at most one element. - No conflict between input and
-transitions: For every , every , and every , the two sets and cannot both be non-empty.
The second condition says: if there is an
Why the
Practical convention: We typically use
1.6 Configurations and Transitions
To formally describe the execution of a PDA, we introduce the notion of a configuration.
1.6.1 Configuration
A configuration is a “snapshot” of the PDA at any instant. It captures everything about the current computation:
where:
— the current state of the control device — the unread portion of the input string (the part not yet consumed) — the current stack contents (entire stack, from top to bottom)
Convention: The stack is written top-first. If
Example: The configuration
Initial configuration:
1.6.2 Transitions Between Configurations
The symbol
Case 1 — Reading an input symbol: If
In words: consume the input symbol
Case 2 —
In words: do NOT consume any input, pop
The key difference between the two cases: in Case 1, the input head advances by one symbol; in Case 2, the input head stays in place.
1.6.3 Multi-Step Computation:
We define
The
1.6.4 Acceptance by a PDA
A string
for some
In plain English: starting from the initial configuration (state
- The entire input has been consumed (remaining input is
) - The current state is accepting (
) - The stack can contain anything (
is arbitrary)
The language recognized by
1.7 Two Acceptance Modes
A PDA can accept a string in two different ways:
- Acceptance by final state: The input is completely consumed and the PDA is in a state
. The stack content is irrelevant. - Acceptance by empty stack: The input is completely consumed and the stack contains only
(effectively empty). The state does not matter.
For nondeterministic PDAs, these two acceptance modes are equivalent: any language accepted by one mode can be accepted by the other (using a different PDA). For deterministic PDAs, however, the two modes are not equivalent.
A subtlety about empty-stack acceptance: Languages accepted by empty stack must be prefix-free — no string in the language is a proper prefix of another string in the language. Once the stack empties on reading
1.8 Worked Example: PDA for
This classic example shows how a PDA uses its stack to count symbols.
Strategy: Push one stack symbol
PDA specification:
- States:
(start), (reading ’s), (reading ’s), (accepting) - Stack alphabet:
- Transitions:
| Transition | Notation | Meaning |
|---|---|---|
| Read first |
||
| Read each subsequent |
||
| Read first |
||
| Read each subsequent |
||
| Input exhausted; |
Trace for input
| Step | State | Remaining Input | Stack (top first) | Rule Applied |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ACCEPT |
The full computation is:
1.9 More PDA Examples
1.9.1 PDA for
Strategy: Push one
- States:
(start, push phase), (pop phase, after ), (accepting) - Transitions:
| Transition | Notation | Meaning |
|---|---|---|
| First |
||
| Each subsequent |
||
| See the |
||
| Each |
||
| All |
1.9.2 PDA for
The language
Strategy: Push all symbols of
- States:
(push phase), (pop phase, after ), (accepting) - Key transitions (push phase, state
, loops): ; ; ; ; ;
- Pivot (on seeing
): ; ; (all move ) - Pop phase (state
, loops): ; - Accept:
(move )
1.9.3 PDA for Balanced Parentheses
The language of balanced (well-formed) parentheses is the prototypical context-free language. Intuitively, each ( must have a matching ) and matched pairs must be properly nested.
- States:
(start), (processing), (accepting) - Transitions:
: — first(: push : — each additional(: push : — each): pop one (matching the() : — input exhausted, stack empty: accept
1.10 PDAs vs FSAs: The Big Picture
- Every regular language can be recognized by a PDA (just simulate the FSA without using the stack).
- PDAs can recognize languages that no FSA can (e.g.,
). - Therefore, the class of context-free languages strictly contains the class of regular languages.
- Regular languages
Languages recognized by PDAs (context-free languages) - Examples of context-free but not regular:
, , balanced parentheses - Examples beyond PDAs:
(requires counting three quantities simultaneously — no stack can do this)
Memory perspective:
- FSA: fixed, bounded memory (only the current state — a fixed number of bits)
- PDA: finite but not fixed — the stack can grow without bound (unbounded memory)
- Key insight: regular languages are about bounded memory; context-free languages require unbounded memory (but with a specific LIFO structure)
1.11 PDAs and Compilers
PDAs are directly connected to how modern compilers work. A compiler is a program that translates source code (e.g., C, Python) into another language (e.g., machine code). It operates in several phases:
- Lexical Analysis (Lexing): Breaks source code into tokens — the smallest meaningful units (keywords, identifiers, operators, etc.). The syntax of tokens is regular, so an FSA (or regular expression engine) performs this phase.
- Syntax Analysis (Parsing): Verifies that the sequence of tokens conforms to the grammar of the programming language. Programming languages have nested structures (balanced brackets, function calls, arithmetic expressions), which are context-free. A PDA performs this phase.
- Semantic Analysis: Checks type correctness, scope rules, etc.
- Code Generation and Optimization: Produces and optimizes the target code.
Why PDAs for parsing? Programming languages have constructs requiring matched/nested structures:
{...}blocks in C/Javabegin...endin Pascal- Parenthesized arithmetic expressions
- Nested function calls
These are precisely the kinds of structures that PDAs can handle and FSAs cannot.
Lexical analysis uses FSAs because tokens (like identifiers, numbers, keywords) follow regular patterns. For example, a Pascal identifier matches the regular pattern <letter>(<letter>|<digit>)*, which is easily recognized by an FSA.
Syntax analysis uses PDAs because grammar rules like “an expression is a term, then an operator, then another expression — possibly parenthesized” are context-free.
“Context-free grammars have played a central role in compiler technology since the 1960s… There is an automaton-like notation, called the ‘pushdown automaton’, that also describes all and only the context-free languages.” — John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman
1.12 The Pumping Lemma for Context-Free Languages (Bar-Hillel Lemma)
Just as the Pumping Lemma for regular languages gives us a tool to prove that certain languages are not regular, there is an analogous tool for context-free languages.
1.12.1 Pumping Lemma for Regular Languages (Recap)
Pumping Lemma (FSA): If
(i.e., ) for any
The contrapositive is the tool for proving non-regularity: if no such decomposition exists for some word in
1.12.2 Bar-Hillel Lemma (Pumping Lemma for Context-Free Languages)
Bar-Hillel Lemma: If
(at least one of or is non-empty) (the “middle” portion is not too long) for any (pumping both and simultaneously keeps the string in )
Key difference from regular Pumping Lemma: In the regular case, we pump a single segment
The intuition comes from parse trees (Chomsky normal form). In a sufficiently tall parse tree, some non-terminal
1.12.3 Contrapositive: Proving Non-Context-Freeness
Bar-Hillel Lemma (Corollary): If for any
The two-player game formulation:
| Player 1 (Adversary) | Player 2 (You) |
|---|---|
| Picks any |
Choose |
| Picks any split |
Find |
You win (and
1.12.4 Classic Example:
Claim:
Proof sketch: Let
The distance from the first
In every case, pumping with
- If
contains only ’s: pumping adds more ’s but no ’s or ’s, giving . - If
contains only ’s: pumping gives . - If
contains only ’s: pumping gives . - If
spans ’s and ’s: pumping adds ’s and ’s but not ’s, giving an unbalanced string not in . - If
spans ’s and ’s: pumping adds ’s and ’s but not ’s, same problem.
In all cases,
1.13 Beyond PDAs: The Limits of Context-Free Languages
Not all languages are context-free. The language
To recognize such languages, we need an even more powerful model: the Turing Machine, which has a full read/write tape (not just a stack). The stack is a destructive memory — once a symbol is popped, it is gone. A tape is persistent — reading does not destroy.
The hierarchy of languages mirrors the hierarchy of machines:
- Regular languages — recognized by FSAs
- Context-free languages — recognized by PDAs (stack memory)
- Context-sensitive and more — recognized by Turing Machines (tape memory)
2. Definitions
- Pushdown Automaton (PDA): A computational model consisting of a finite control unit, an input tape, and an unbounded stack. Formally a 7-tuple
. PDAs recognize exactly the class of context-free languages. - Deterministic Pushdown Automaton (DPDA): A PDA where (1)
for all (at most one transition at each step), and (2) implies for all (no conflict between input-reading and -transitions). - Nondeterministic PDA: A PDA where
may contain multiple possible transitions. The PDA accepts if some sequence of choices leads to acceptance. - Stack: A last-in, first-out (LIFO) data structure used by a PDA as its main memory. Supports two operations: push (add to top) and pop (remove from top).
- Stack Alphabet (
): The finite set of symbols that may appear on the PDA’s stack. Typically includes the bottom-of-stack marker . - Bottom-of-Stack Symbol (
): A special symbol placed at the bottom of the PDA’s stack initially. It is never removed and never duplicated. When is on top, the stack is effectively empty. - Input Alphabet (
): The finite set of symbols that the PDA reads from its input tape. Distinct from conceptually, though they may share symbols. - Transition Function (
): The function specifying PDA moves. A transition means: in state , reading (or ) from input and from the stack top, move to state and replace with string . -move: A PDA transition of the form that does not consume any input symbol. The PDA changes state and modifies the stack “spontaneously,” without reading the next character. -rule (DPDA condition): If there is an -transition from state with stack top , then there must be no input-reading transition from the same state with the same stack top . This ensures determinism.- Configuration: A triple
representing a complete “snapshot” of a PDA: current state , unread input , and stack contents (top to bottom). Also called a “PDA instantaneous description.” - Transition Between Configurations (
): A single computation step. if ; or if . - Reflexive Transitive Closure (
): means there is a sequence of zero or more steps from configuration to . - Acceptance by Final State: A string
is accepted if for some and . The stack content at the end is irrelevant. - Acceptance by Empty Stack: A string
is accepted if for some state (not necessarily in ). For DPDAs, these two acceptance modes are not equivalent. - Context-Free Language (CFL): A language recognized by a pushdown automaton, or equivalently, generated by a context-free grammar. Every regular language is context-free, but not vice versa.
- Pumping Lemma (Regular Languages): If
is regular, there exists such that every with has a split with , , and for all . - Bar-Hillel Lemma (Pumping Lemma for CFLs): If
is a context-free language, there exists such that every with has a split with , , and for all . - Compiler: A program that translates source code in one language (e.g., C) into another language (e.g., machine code), typically via multiple phases: lexical analysis, syntax analysis, semantic analysis, and code generation.
- Lexical Analysis (Lexing): The first phase of compilation; breaks source code into tokens (keywords, identifiers, operators). Uses FSAs (regular languages) to recognize token patterns.
- Syntax Analysis (Parsing): The second phase of compilation; checks that the sequence of tokens conforms to the language grammar and constructs a parse tree. Uses PDAs (context-free languages) to handle nested language structures.
- Token: The smallest meaningful unit in a programming language (e.g., an identifier
sum, an operator+, a keywordif). Recognized by lexical analysis. - Parse Tree (Syntax Tree): A tree structure built during syntax analysis that represents the grammatical structure of the source code. Leaf nodes are tokens; internal nodes are grammar rules.
- Abstract Syntax Tree (AST): A simplified parse tree that represents the logical structure of the source code, used in semantic analysis, optimization, and code generation.
- Prefix-Free Language: A language
where no string in is a proper prefix of another string in . Languages accepted by a DPDA via empty stack must be prefix-free.
3. Formulas
- PDA formal definition:
where - Transition notation:
— read from input (or for spontaneous), pop from stack, push - Push
onto stack: replace top with — write - Pop top
: replace top with — write - Leave stack unchanged: replace top
with — write - DPDA condition 1:
for all , , - DPDA condition 2:
for all , , - Configuration:
where , (remaining input), (stack, top first) - Transition (input symbol):
when - Transition (
-move): when - Acceptance by final state:
for some , - Language recognized:
- Pumping Lemma (regular):
regular s.t. with , split , , , - Bar-Hillel Lemma (CFL):
context-free s.t. with , split , , , - Contrapositive (Bar-Hillel):
is not CFL if , with such that splits with and : with
4. Practice
4.1. Construct a DPDA for (Lab 6, Task 1)
Build a DPDA that recognizes the language
Click to see the solution
Key Concept: For each
PDA specification:
- States:
(start), (reading ’s), (reading ’s), (accepting) - Stack alphabet:
- States:
Transitions:
Transition Notation Meaning First : push two ’sEach subsequent : push two more ’s (net: replace top with , adding two)First : pop oneEach subsequent : pop oneAll ’s consumed; acceptNote on the push step: When reading
with on top, we replace with — effectively, we keep the existing and add two more on top, so the stack grows by two per . Equivalently, since each should add two symbols: we replace (adding two) which matches the ratio.Trace for input
( , ): : stack = : stack = : stack = : ACCEPT
Trace for input
( , ): : stack = : stack = (net +2: adds two) : stack = : stack = : stack = : stack = — (ERROR: stack underflow — wrong, recheck)
Correction: Let’s recount. For
: push 2 for first (stack = ), then replace top with for second : stack = (4 ’s? No — with top replaced by gives — that’s 3 ’s + ). We need symbols for .Revised approach: A cleaner strategy: for each
, push two ’s unconditionally. Use a separate state to push the second .Transition Notation Meaning First : push firstSpontaneous: push second Subsequent (first push)… … … Simplest correct approach: For each
, push two ’s by using a helper state:- States:
(start), (just read , need to push second ), (ready to read or ), (reading ’s), (accepting)
Transition Notation Meaning First : push onePush second (spontaneous)Another : push first of two ’sStart reading ’s: pop oneEach : pop oneStack empty: accept
Answer: The DPDA using a helper state to push two
4.2. Construct a DPDA for Arithmetic Expression Parentheses (Lab 6, Homework 1)
Construct a DPDA that recognizes the language of well-formed parentheses of arithmetic expressions (binary operations). The alphabet is
Examples in the language: (a + a), ((a) + (a + a)), ((a + a)) The language consists of syntactically valid arithmetic expressions with parenthesized subexpressions.
Click to see the solution
Key Concept: This problem is about recognizing a simple expression grammar. The core constraint is that parentheses must be balanced: each ( must have a matching ), properly nested. The
Simplification: For the purpose of DPDA construction, the key property is that the parentheses must be balanced. The
Grammar (informally):
- An expression is: a term, or
(expression), or expression+expression
For a simple DPDA approach tracking only parenthesis balance:
States:
(processing), (accepting)- Stack alphabet:
where marks an open(
- Stack alphabet:
Transitions (loops on
):Notation Meaning Open (: push (stack was empty)Open (inside another: pushClose ): pop matchingRead term : no stack changeRead term inside parentheses: no stack changeRead operator outside parentheses: no stack change Read operator inside parentheses: no stack change Accept:
: — balanced.Trace for
: : stack = : stack = : stack = : stack = : stack = : ACCEPT
Answer: The DPDA tracks parenthesis balance via the stack, accepting when all parentheses are matched and the input is fully consumed.
4.3. Construct a DPDA for (Lab 6, Task 2)
Build a DPDA that recognizes
(The string consists of a non-empty string
Click to see the solution
Key Concept: Push all symbols of
- PDA specification:
- States:
(pushing ), (pushing ), (popping ), (popping ), (accepting) - Stack alphabet:
- States:
- Phase 1 — Push
(state , loops): ; ; ;
- Transition to
-push phase (state ): On reading the first or symbol, switch to : ; ; ;
- Phase 2 — Push
(state , loops): ; ;
- Pivot on
( or if empty): ; (top is a -symbol: switch to pop- phase) ; (no was pushed, skip to pop- phase: )
- Phase 3 — Pop
(state , loops): ; (match , )- Transition to pop-
phase when hitting an -symbol: on when top is or : ;
- Phase 4 — Pop
(state , loops): ; (match , )
- Accept:
:
Answer: The DPDA with phases for pushing
4.4. Construct a DPDA for Balanced Brackets and Parentheses (Lab 6, Task 3)
Build a DPDA that recognizes the language of nested and balanced brackets and parentheses over the alphabet
Examples of strings in the language: (([])())(), (())[] Examples NOT in the language: ([(]))()(), ([)]
Click to see the solution
Key Concept: Use the stack to track open delimiters. When ( is seen, push a marker [ is seen, push a marker ) is seen, pop the top and check it is ] is seen, pop and check it is
Note: A key challenge is that ([)] must be rejected — the closing symbols must match the most recently opened one. The stack’s LIFO property enforces this naturally.
PDA specification:
- States:
(start, processing), (accepting) - Stack alphabet:
where marks(and marks[
- States:
Transitions (all loops on
except the final accept):Notation Meaning Open (on empty stack: pushOpen (with on top: pushOpen (with on top: pushOpen [on empty stack: pushOpen [with on top: pushOpen [with on top: pushClose )with on top: pop (matched!)Close ]with on top: pop (matched!)Accept:
: — all matched, stack has only .Rejection (implicitly): If
)is read but (not ) is on top, there is no defined transition, so the PDA gets stuck and rejects. This correctly rejects strings like([)].Trace for input
: : stack = : stack = : stack = : stack = : ACCEPT
Answer: The DPDA above recognizes the language of nested and balanced brackets and parentheses over
4.5. Construct a DPDA for (Lab 6, Task 4)
Build a DPDA that recognizes
Click to see the solution
Key Concept: Unlike
PDA specification:
- States:
(processing), (accepting) - Stack alphabet:
on the stack means “more ’s seen so far”; means “more ’s seen so far”
- States:
Transitions (all loops on
):Notation Meaning Read , stack balanced so far: push (now +1 )Read , currently have excess ’s: push moreRead , currently have excess ’s: cancel oneRead , stack balanced so far: push (now +1 )Read , currently have excess ’s: push moreRead , currently have excess ’s: cancel oneAccept:
: — all cancelled out, stack holds : counts equal; accept.Trace for input
: : stack = (1 excess ) : stack = (cancelled) : stack = (1 excess ) : stack = (cancelled) : ACCEPT
Trace for input
(should reject since ): : stack = : stack = : stack =- Input exhausted; stack is
(not just ); no -accept transition applies. REJECT
Answer: The DPDA above uses the stack as a signed counter to recognize
4.6. Construct a DPDA for (Lab 6, Task 5)
Build a DPDA that recognizes
Click to see the solution
Key Concept: The string has the form
- Phase 1 (outer
’s): Push copies of for the leading ’s. - Phase 2 (inner
’s): Push copies of for the leading ’s (on top of the ’s). - Phase 3 (inner
’s): Pop one per (matching the inner ’s with inner ’s). - Phase 4 (outer
’s): Pop one per (matching the outer ’s with outer ’s).
States:
(reading outer ’s), (reading inner ’s), (reading inner ’s), (reading outer ’s), (accepting)Transitions:
Transition Notation Meaning First outer : pushMore outer ’s: pushFirst inner : push on top of ’sMore inner ’s: pushFirst inner : pop oneMore inner ’s: popFirst outer : pop one (all ’s gone)More outer ’s: popAll matched: accept Trace for input
is too short (minimum: ):Trace for
( ): : stack = : stack = : stack = : stack = : ACCEPT
Answer: The DPDA with phases for outer
4.7. Prove That Is Not Context-Free (Tutorial 6, Example 1)
Use the Bar-Hillel Lemma (Pumping Lemma for context-free languages) to prove that
Click to see the solution
Key Concept: In
Assume for contradiction that
is context-free. Let be the pumping length given by the Bar-Hillel Lemma.Choose the word
. Note .Consider any split
with and .Restrict where
can lie: The distance from the first to the last is characters. Since , the window cannot span all three types of symbols simultaneously. It can cover:- Only
’s, or only ’s, or only ’s, or ’s and ’s (but not ’s), or ’s and ’s (but not ’s)
- Only
Pump with
(pump up): Consider . In every case:- If
contains only ’s: pumping adds ’s but no ’s or ’s. The result has more ’s than ’s and ’s. . - If
contains only ’s: pumping adds ’s but no ’s or ’s. . - If
contains only ’s: pumping adds ’s but no ’s or ’s. . - If
spans ’s and ’s: pumping adds more ’s and ’s but no extra ’s. . - If
spans ’s and ’s: pumping adds more ’s and ’s but no extra ’s. .
- If
Conclusion: In every case,
. The Bar-Hillel Lemma is violated. Therefore is not context-free.
Answer:
4.8. Construct a DPDA for (Tutorial 6, Example 2)
Construct a Deterministic Pushdown Automaton (DPDA) that recognizes
Click to see the solution
Key Concept: Use the stack to count
PDA specification:
- States:
(start), (reading ’s), (reading ’s), (accepting) - Stack alphabet:
- Input alphabet:
- States:
Transitions:
Transition Notation Meaning Read first ; push on top ofRead additional ’s; push each timeRead first ; pop oneRead additional ’s; pop one each timeInput exhausted; on top means all ’s were matched; acceptVerification that this is a DPDA:
- Each
entry has exactly one output: condition 1 satisfied. - The
-transition uses stack top . No input-reading transition from has on top: condition 2 satisfied.
- Each
Trace for input
:Step State Remaining Input Stack Rule 1 : push2 : push3 : pop4 : pop5 : accept6 ACCEPT Full configuration sequence:
Answer: The DPDA with states
4.9. Construct a DPDA for (Tutorial 6, Example 3)
Construct a DPDA that recognizes
Click to see the solution
Key Concept: Push one
PDA specification:
- States:
(start, push phase), (pop phase, after ), (accepting) - Stack alphabet:
- States:
Transitions:
Transition Notation Meaning First before : pushEach subsequent before : pushRead the : keep stack unchanged, switch to pop phaseEach after : pop oneAll ’s matched; acceptTrace for input
: : stack = : stack = (unchanged) : stack = : ACCEPT
Trace for input
: : stack = : stack = : stack = : stack = : stack = : ACCEPT
Answer: The DPDA with states
4.10. Construct a DPDA for (Tutorial 6, Example 4)
Construct a DPDA that recognizes
Click to see the solution
Key Concept: Push every symbol of
PDA specification:
- States:
(push phase), (pop phase), (accepting) - Stack alphabet:
where represents and represents
- States:
Transitions:
Push phase (
, self-loops — push symbols of ):Notation Meaning First : pushFirst : pushSubsequent with on top: pushSubsequent with on top: pushSubsequent with on top: pushSubsequent with on top: pushPivot (on reading
, move , keep stack unchanged):Notation Meaning was empty: switch to pop mode seen with on top: switch to pop mode seen with on top: switch to pop modePop phase (
, self-loops — match ):Notation Meaning Read , top is : match, popRead , top is : match, popAccept:
: — all matched, accept.Trace for input
(so , ): : stack = : stack = : stack = (unchanged) : stack = : stack = : ACCEPT
Answer: The DPDA with states